import React, {Component} from 'react'
import {Modal} from 'antd'

class ModalComponent extends Component {
    state = {
        visible: false
    }

    // componentWillReceiveProps(nextProps, nextContext) {
    //     const {visible} = nextProps;
    //     this.setState({visible})
    // }

    onCancel = () => {
        this.setState({visible: false});
    }

    render() {
        const {visible} = this.state;
        const {children, clazz, attributes} = this.props;
        const attr = attributes || {};
        const modalProps = {
            title: '编辑',
            visible,
            width: 660,
            getContainer: () => clazz ? document.querySelector('.' + clazz) : document.body,
            centered: true,
            footer: null,
            destroyOnClose: true,
            onCancel: this.onCancel,
            ...attr
        }
        return (
            <>
                <Modal {...modalProps}>
                    {children}
                </Modal>
            </>
        )
    }
}

export default ModalComponent;